import numpy as np

#weight function
def w_function(x,y,tau):
    return np.exp(-np.dot((x-y).T,x-y)/tau)

#preparation
X_test = np.loadtxt('X_test.txt', delimiter=',')
y_test = np.loadtxt('y_test.txt', delimiter=',')
n = X_test.shape[1]#feature number
m = X_test.shape[0]
w = np.zeros((m,1))
x_pred = 11# whose value wanted to be predicted
for i in range(m):
    w[i][0] = w_function(X_test[i], x_pred, x_pred)

theta = np.zeros((n+1,1))
iteration = 100
learning_rate = 0.01

#grad descent
for i in range(iteration):
    theta = theta - learning_rate * np.dot(X_test.T,np.dot(X_test,theta) - y_test) * w

#predict
prediction = np.dot(x_pred.T,theta)
print(theta)
print(prediction)